#!/usr/bin/env ruby
# YAML structure defining a SAX parsing scheme for fmpxmllayout xml.
# The initial object of this parse should be a new instance of Rfm::Layout.
---
attach_elements: _meta
attach_attributes: _meta
elements:
- name: doctype
  attach: none
  attributes:
  - name: value
    as_name: doctype
- name: fmpxmllayout
  attach: none
- name: errorcode
  attach: none
  before_close: :check_for_errors
  attributes:
  - name: text
    as_name: error
- name: product
  as_name: product
- name: layout
  attach: none
  attributes:
  - name: database
    as_name: database
  - name: NAME
    as_name: name
- name: field
  attach:
  - cursor
  - Rfm::Metadata::FieldControl
  - :new
  - ivg(:meta)
  # Must use before_close handler to attach, since field_mapping must be applied to value-list key name.
  before_close: [object, ':element_close_handler']
  # # Used to be 'object.meta', but that required sloppy 'loaded' indicator handling (or infinite loop),
  # # so now just referring to raw inst var @meta, instead of method .meta.
  # # Need to assume attributes may or may not be included in start_element call.
  # handler: [object.instance_variable_get('@meta'), handle_new_field_control, _attributes]
  # # attach_attributes isn't doing anything when used with new-element-handler.
  attach_attributes: private
  delimiter: name
  elements:
  # This config doesn't use the creation handler, so it should work with ox.
  - name: style
    #element_handler: [object, handle_style_element, _attributes]
    attach: none
    #attach: [cursor, object, handle_style_element, _attributes]
    #attach_attributes: none
    attributes:
    - name: valuelist
      as_name: value_list_name
      #translate: translate_style_value
- name: valuelists
  attach: none
- name: valuelist
  #class: Array
  attach: [_meta, Array, ':new']
  as_name: value_lists
  delimiter: name
  elements:
  - name: value
    #class: Rfm::Metadata::ValueListItem
    attach: [array, 'Rfm::Metadata::ValueListItem', ':allocate']
    before_close: replace(@value.to_s)
    attach_attributes: private
    attributes:
    - name: display
      as_name: display
    - name: text
      as_name: value


# Works - doesn't use Handler method.
# ---
# attach_elements: _meta
# attach_attributes: _meta
# elements:
# - name: doctype
#   attach: none
#   attributes:
#   - name: value
#     as_name: doctype
# - name: FMPXMLLAYOUT
#   attach: none
# - name: ERRORCODE
#   attach: none
#   # TODO: Build check_for_errors method in Layout class.
#   #before_close: 'check_for_errors'
#   attributes:
#   - name: text
#     as_name: error
# - name: PRODUCT
#   as_name: product
# - name: LAYOUT
#   attach: none
#   attributes:
#   - name: DATABASE
#     as_name: database
#   - name: NAME
#     as_name: name
# - name: FIELD
#   class: Rfm::Metadata::FieldControl
#   as_name: field_controls
#   delimiter: name
#   attach_attributes: private
#   attributes:
#   - name: NAME
#     as_name: name
#   elements:
#   - name: STYLE
#     attach: none
#     # Add logic for 3rd level of prefs, so FieldControl pref captures this attach_attributes instead having to explicitly define here.
#     attach_attributes: private
#     attributes:
#     - name: TYPE
#       as_name: type
#     - name: VALUELIST
#       as_name: valuelist
# - name: VALUELISTS
#   attach: none
# - name: VALUELIST
#   # TODO: Disabling this breaks the delimiter.
#   #attach: shared
#   class: Array
#   as_name: value_lists
#   delimiter: NAME
#   elements:
#   - name: VALUE
#     class: Rfm::Metadata::ValueListItem
#     before_close: replace(@value.to_s)
#     attach_attributes: private
#     attributes:
#     - name: DISPLAY
#       as_name: display
#     - name: text
#       as_name: value



# Works !!!
# ---
# elements:
# - name: FMPXMLLAYOUT
#   attach: none
#   attach_attributes: shared
# - name: ERRORCODE
#   as_name: error
#   attach: shared
#   compact: true
# - name: PRODUCT
#   attach: none
#   attach_attributes: shared
# - name: LAYOUT
#   attach: none
#   attach_attributes: shared
# - name: FIELD
#   class: Rfm::Metadata::FieldControl
#   as_name: field_controls
#   delineate_with_hash: name
#   attributes:
#   - name: NAME
#     as_name: name
#   elements:
#   - name: STYLE
#     attach: none
#     attributes:
#     - name: TYPE
#       as_name: type
#     - name: VALUELIST
#       as_name: valuelist
# - name: VALUELISTS
#   attach: none
# - name: VALUELIST
#   class: Array
#   as_name: value_lists
#   delineate_with_hash: NAME
#   elements:
#   - name: VALUE
#     # This turns the potential hash into a string
#     class: String
#     # Then we place the main attribute into the string's data.
#     before_close: replace text
#     attributes:
#     - name: DISPLAY
#       as_name: display


